/**
 *   Copyright (c) fanguangping. All rights reserved.
 *   The use and distribution terms for this software are covered by the
 *   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 *   which can be found in the file epl-v10.html at the root of this distribution.
 *   By using this software in any fashion, you are agreeing to be bound by
 * 	 the terms of this license.
 *   You must not remove this notice, or any other, from this software.
 **/
package org.jfunny.core.sys.impl.clojure;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.jfunny.core.ds.Statement;
import org.jfunny.core.meta.Mapping;
import org.jfunny.core.meta.Namespace;
import org.jfunny.core.sys.SysLoader;
import org.jfunny.core.sys.SysPreparable;

/**
 * 
 * @author fanguangping
 *
 */
public class SysTemplate implements SysPreparable{

	@Override
	public void prepare(Statement statement) {
		List<String> funcArgs = SysFunctionHelper.getArgContents(statement);
		
		String name = funcArgs.get(0);
		String key = funcArgs.get(1);
		String value = funcArgs.get(2);

		Mapping mapping = new Mapping(name, key, value, false);
		addToMap(SysLoader.MAPPINGS, SysLoader.currentNamespace, mapping);
	}

	private static void addToMap(Map<Namespace, List<Mapping>> map, Namespace namespace, Mapping mapping) {
		if (map.get(namespace) == null) {
			map.put(namespace, new ArrayList<Mapping>());
		}
		map.get(namespace).add(mapping);
	}
}
